package cn.itcast.controller;

import cn.itcast.domain.Yuancailiao;
import cn.itcast.service.UserService;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/manage")
public class ManageController {

    @Resource
    private UserService service;

    @RequestMapping("/rawmaterial.do")
    @ResponseBody
    public List<Yuancailiao> rawMaterial(String pageNum){
        PageHelper.startPage(Integer.parseInt(pageNum),1);
        List<Yuancailiao> list=new ArrayList<>();
        list=service.findmatserial();
        return list;
    }

    @RequestMapping("/deletemateial.do")
    @ResponseBody
    public Map<String,Object> deleteMaterial(Integer id){
        Map<String,Object> maplist=new HashMap<>();
        Boolean flag=service.deletemat(id);
        String result=null;
        if(flag){
            result="1";
        }else{
            result="0";
        }
        maplist.put("result",result);
        return maplist;
    }

    @RequestMapping("/findmaterialById.do")
    @ResponseBody
    public Yuancailiao findmaterialById(Integer id){
        Yuancailiao yl =service.findmaterById(id);
        return yl;
    }


    @RequestMapping(value = "/modifymaterial.do",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> modifymaterial(Yuancailiao yl){
        String result=null;
        Map<String,Object> maplist=new HashMap<>();
        Boolean flag=service.modifymater(yl);
        if(flag){
            result="1";
        }else {
            result="0";
        }
        maplist.put("result",result);
     return maplist;
    }

    @RequestMapping("/findCount.do")
    @ResponseBody
    public Map<String,Object> findCount(){
        Map<String,Object> maplist=new HashMap<>();
        Integer result=service.findcount();
        maplist.put("result",result);
        return maplist;
    }


}
